/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sie_invdis;


import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;

import org.jfree.ui.ApplicationFrame;

import java.awt.*;
import java.awt.event.*;






public class graficacion_varios_barras extends ApplicationFrame{

     private JFreeChart chart=null;
    private ChartPanel panel=null;





  public graficacion_varios_barras(String title,CategoryDataset data,String fnombregraf,String fnombreorizo)
    {
        super(title);
        
        chart=crearChart(data,fnombregraf,fnombreorizo);

        panel = new ChartPanel(chart,false);

        panel.setPreferredSize(new Dimension(800,600));
        panel.updateUI();
        this.setContentPane(panel);
        this.setVisible(false);
        //this.update(this.getGraphics());

        this.setVisible(true);
    }

    

    private static JFreeChart crearChart(CategoryDataset data,String subtitulo,String tituejeori)
    {
        //createLineChart
        JFreeChart chart= ChartFactory.createBarChart3D(
                subtitulo,        //Nombre de la gráfica
                tituejeori,               //Nombre del eje Horizontal
                "Monto de Venta",                  //Nombre del eje vertical
                data,                       //Data
                PlotOrientation.VERTICAL, //Orientación
                true,                       //Incluir leyenda
                true,                       //Información al pasar el mouse
                true);                      //URls
        //Dar color al fondo del panel
        chart.setBackgroundPaint(Color.ORANGE);
        //Dar color a cada categoria
        CategoryPlot plot =(CategoryPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.BLUE);
        //Color del fondo del gráfico
        plot.setBackgroundPaint(Color.WHITE);
        //Lineas divisorias
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.BLACK);
        //Calculo de los valores en el eje x
        final NumberAxis rangeAxis=(NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);
        //Dar color a cada barra
        GradientPaint gp0= new GradientPaint(0.0f,0.0f,Color.BLUE,0.0f,0.0f,new Color(0,0,64));
        GradientPaint gp1= new GradientPaint(0.0f,0.0f,Color.green,0.0f,0.0f,new Color(0,64,0));
        GradientPaint gp2= new GradientPaint(0.0f,0.0f,Color.red,0.0f,0.0f,new Color(64,0,0));
        renderer.setSeriesPaint(0,gp0);
        renderer.setSeriesPaint(1,gp1);
        renderer.setSeriesPaint(2,gp2);

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(Math.PI/6.0));
        return chart;
    }



     @Override public void windowClosing(WindowEvent e) {

      this.dispose();


     }


}
